<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    const calculate = async (num1, num2, operation) => {
        return new Promise(await ((resolve, reject) => {
            switch (operation) {
                case 'add':
                    resolve(num1 + num2);
                case'subtract':
                    resolve(num1 - num2);
                case'multiply':
                    resolve(num1 * num2);
                case 'divide':
                    if (num2 === 0) {
                        resolve('除数不能为0');
                    }
                    resolve(num1 / num2);
                default:
                    resolve('无效的操作');
            }
        }))
    };
    // 将其改造为一个异步函数，并且定义一个async函数calculateResult，在其中完成3*5+8的计算
    const calculateResult = async (num1, num2, num3) => {
        // 计算乘法出结果
        const calculateMultiplyResult = await calculate(num1, num2, 'multiply');
        // 计算最终结果
        return  await calculate(calculateMultiplyResult, num3, 'add');
    }
    calculateResult(3, 5, 8).then((resolve) => {
        console.log("最终结果为：" + resolve);
    })


</script>
</body>
</html>